/*长连接测试1：创建一个客户端持续给服务器发送数据，直到超过超时时间看看是否正常*/
#include "../server.hpp"

int main()
{
    Socket cli_sock;
    cli_sock.CreateClient(8500, "127.0.0.1");
    std::string req = "GET /hello HTTP/1.1\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n";
    while (1)
    {
        assert(cli_sock.Send(req.c_str(), req.size()) != -1);
        char buf[1024];
        int n = cli_sock.Recv(buf, sizeof(buf) - 1);
        if (n <= 0)
        {
            if (n == 0)
            {
                std::cout << "Server closed connection" << std::endl;
            }
            else
            {
                std::cerr << "Recv error: " << strerror(errno) << std::endl;
            }
            break;
        }

        buf[n] = '\0';
        std::cout << buf << std::endl;

        sleep(15);
    }
    cli_sock.Close();
    return 0;
}